package com.weiwen.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.weiwen.domain.News;
import com.weiwen.domain.NewsType;
import com.weiwen.service.NewsTypeService;
import com.weiwen.util.DateUtil;

public class NewsTypeAction extends ActionSupport{
  
	private static final long serialVersionUID = -1849872876140485078L;
	private NewsTypeService newsTypeService;
	private Map resultMap;
	private News news;
	
	public News getNews() {
		return news;
	}
	public void setNews(News news) {
		this.news = news;
	}

	
	
	public Map getResultMap() {
		return resultMap;
	}
	public void setResultMap(Map resultMap) {
		this.resultMap = resultMap;
	}
 
	public NewsTypeService getNewsTypeService() {
		return newsTypeService;
	}
	public void setNewsTypeService(NewsTypeService newsTypeService) {
		this.newsTypeService = newsTypeService;
		
	}
	 
	
	public String queryMoreNews(){
		System.out.println("query more news action start...");
		HashMap param = new HashMap();
		int id=news.getTypeId();
		System.out.println(id);
		 
		if(news.getTypeId() >= 1000){
		param.put("newtype", news.getTypeId());
		}
		
		if(DateUtil.checkDateStr(news.getEntryTime())){
			//if(news.getEntryTime() != null && !"".endsWith(news.getEntryTime().trim()))
			//news.getEntryTime().trim()
			//������������ʽ�������Ĳ����ǲ����Լ���Ҫ�����ڸ�ʽ�ַ�
			//����ǰѲ�����ܴ���ȥ
			param.put("timepoint", news.getEntryTime());
		}
		List<News> newses = newsTypeService.getRefeshNews(param);
		System.out.println(newses);
		for(News news : newses){
			System.out.println(news.getTitle());
		}
		System.out.println("query more news action end...");
		resultMap = new HashMap();
		resultMap.put("news", newses);
		
		return SUCCESS;
	}
	
	public String queryRefeshNews(){
		System.out.println("query refresh news action start...");
		HashMap param = new HashMap();
		int id=news.getTypeId();
		System.out.println(id);
		System.out.println(news.getEntryTime());
		 
		if(news.getTypeId() >= 100){
		param.put("newtype", id);
		}
		if(DateUtil.checkDateStr(news.getEntryTime())){
			
			param.put("timepoint", news.getEntryTime());
		}
		System.out.println(param.size());
		List<News> newses = newsTypeService.getRefeshNews(param);
		System.out.println(newses);
		for(News news : newses){
			System.out.println(news.getTitle());
		}
		System.out.println("query refresh news action end...");
		resultMap = new HashMap();
		resultMap.put("news", newses);
		return SUCCESS;
	}
	
	public String queryAllNewsTypes(){
		System.out.println("query all news types start...");
		List<NewsType> newstypes = newsTypeService.getAllNewsTypes();
		System.out.println(newstypes);
		System.out.println("query all news types end...");
		resultMap = new HashMap();
		resultMap.put("newstype", newstypes);
		return SUCCESS;
	}
	public static void main(String[] args) {
		
	}
	
}
